@karinjs/adapter-qqbot 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # qaq
2
+
3
+ 开发中...
4
+
5
+ 如需使用:
6
+ 在`config\plugin\@karinjs\adapter-qqbot`创建`config.yaml`
7
+ 输入以下内容,请自行配置账号。当前`Markdown`仅支持`旧图文模板`和`原生`
8
+
9
+ ```yaml
10
+ # 全局默认配置 以下所有配置均可在账号配置中单独配置
11
+ default:
12
+ # 获取调用凭证的api
13
+ accessTokenApi: https://bots.qq.com/app/getAppAccessToken
14
+ # 沙盒api
15
+ sandBoxApi: https://sandbox.api.sgroup.qq.com
16
+ # 正式环境api
17
+ qqBotApi: https://api.sgroup.qq.com
18
+ # 机器人发送模式 0-直接发送 1-原生Markdown 3-旧图文模板Markdown 4-纯文模板Markdown 5-自定义处理
19
+ sendMode: 0
20
+ # 是否开启沙盒环境
21
+ sandBox: false
22
+ # 是否启用频道机器人 未适配
23
+ guild: false
24
+ # 频道机器人模式 0-公域机器人 1-私域机器人
25
+ guildMode: 0
26
+
27
+ # 机器人Markdown模板ID 只有在sendMode为3或4时有效
28
+ templateId: ""
29
+
30
+ # 机器人旧图文模板Markdown配置
31
+ oldTemplate:
32
+ # 开头文字
33
+ textStartKey: text_start
34
+ # 图片描述
35
+ imgDescKey: img_dec
36
+ # 图片地址
37
+ imgUrlKey: img_url
38
+ # 结尾文字
39
+ textEndKey: text_end
40
+
41
+ # 机器人纯文模板Markdown配置
42
+ textTemplate:
43
+ - text_0
44
+ - text_1
45
+ - text_2
46
+ - text_3
47
+ - text_4
48
+ - text_5
49
+ - text_6
50
+ - text_7
51
+ - text_8
52
+ - text_9
53
+
54
+ # 文本中的url转二维码白名单 配置后将不转换这些url为二维码
55
+ exclude: []
56
+ # 接受到消息后对文本进行表达式处理
57
+ regex: [
58
+ {
59
+ # 表达式
60
+ reg: "^#",
61
+ # 替换为
62
+ rep: "",
63
+ },
64
+ ]
65
+
66
+ # 账号配置列表
67
+ accounts:
68
+ default:
69
+ # 机器人ID 必须为字符串
70
+ appId: "123456789"
71
+ # 机器人密钥
72
+ secret: "123456789"
73
+ # 机器人发送模式 0-直接发送 1-原生Markdown 3-旧图文模板Markdown 4-纯文模板Markdown 5-自定义处理
74
+ sendMode: 0
75
+ # 文本中的url转二维码白名单 配置后将不转换这些url为二维码 优先级高于全局配置
76
+ exclude: []
77
+ # 接受到消息后对文本进行表达式处理 优先级高于全局配置
78
+ regex: []
79
+
80
+ ```
@@ -0,0 +1,69 @@
1
+ # 全局默认配置 以下所有配置均可在账号配置中单独配置
2
+ default:
3
+ # 获取调用凭证的api
4
+ accessTokenApi: https://bots.qq.com/app/getAppAccessToken
5
+ # 沙盒api
6
+ sandBoxApi: https://sandbox.api.sgroup.qq.com
7
+ # 正式环境api
8
+ qqBotApi: https://api.sgroup.qq.com
9
+ # 机器人发送模式 0-直接发送 1-原生Markdown 3-旧图文模板Markdown 4-纯文模板Markdown 5-自定义处理
10
+ sendMode: 0
11
+ # 是否开启沙盒环境
12
+ sandBox: false
13
+ # 是否启用频道机器人
14
+ guild: false
15
+ # 频道机器人模式 0-公域机器人 1-私域机器人
16
+ guildMode: 0
17
+
18
+ # 机器人Markdown模板ID 只有在sendMode为3或4时有效
19
+ templateId: ""
20
+
21
+ # 机器人旧图文模板Markdown配置
22
+ oldTemplate:
23
+ # 开头文字
24
+ textStartKey: text_start
25
+ # 图片描述
26
+ imgDescKey: img_dec
27
+ # 图片地址
28
+ imgUrlKey: img_url
29
+ # 结尾文字
30
+ textEndKey: text_end
31
+
32
+ # 机器人纯文模板Markdown配置
33
+ textTemplate:
34
+ - text_0
35
+ - text_1
36
+ - text_2
37
+ - text_3
38
+ - text_4
39
+ - text_5
40
+ - text_6
41
+ - text_7
42
+ - text_8
43
+ - text_9
44
+
45
+ # 文本中的url转二维码白名单 配置后将不转换这些url为二维码
46
+ exclude: []
47
+ # 接受到消息后对文本进行表达式处理
48
+ regex: [
49
+ {
50
+ # 表达式
51
+ reg: "^#",
52
+ # 替换为
53
+ rep: "",
54
+ },
55
+ ]
56
+
57
+ # 账号配置列表
58
+ accounts:
59
+ default:
60
+ # 机器人ID 必须为字符串
61
+ appId: "123456789"
62
+ # 机器人密钥
63
+ secret: "123456789"
64
+ # 机器人发送模式 0-直接发送 1-原生Markdown 3-旧图文模板Markdown 4-纯文模板Markdown 5-自定义处理
65
+ sendMode: 0
66
+ # 文本中的url转二维码白名单 配置后将不转换这些url为二维码 优先级高于全局配置
67
+ exclude: []
68
+ # 接受到消息后对文本进行表达式处理 优先级高于全局配置
69
+ regex: []
@@ -0,0 +1,167 @@
1
+ import WebSocket from 'ws';
2
+ import { LoggerLevel } from 'node-karin';
3
+ import { AccountCfgType } from '../utils/index.js';
4
+ import { IdType, FileType, PathType, V2ApiType, UploadMediaOptions, SendMessageOptions, UploadMediaResponse, SubEvent } from '../types/index.js';
5
+ export interface SendMessageResponse {
6
+ /** 消息唯一ID */
7
+ id: string;
8
+ /** 发送时间 */
9
+ timestamp: number;
10
+ }
11
+ /**
12
+ * {key: xxx, values: xxx},模版内变量与填充值的kv映射
13
+ */
14
+ export type Params = Array<{
15
+ key: string;
16
+ values: string[];
17
+ }>;
18
+ export declare class QQBotApi {
19
+ #private;
20
+ /**
21
+ * 开发者的appId
22
+ */
23
+ appId: string;
24
+ /**
25
+ * Bot的昵称
26
+ */
27
+ nick: string;
28
+ /**
29
+ * wss地址
30
+ */
31
+ wssUrl: string;
32
+ /**
33
+ * wss连接
34
+ */
35
+ wss: WebSocket;
36
+ seq: number;
37
+ /**
38
+ * 心跳内容
39
+ */
40
+ heartbeat: {
41
+ op: 1;
42
+ d: null | number;
43
+ session_id: string;
44
+ };
45
+ /**
46
+ * 心跳生命周期 单位:毫秒
47
+ */
48
+ heartbeat_interval: number;
49
+ /**
50
+ * 请求头 用于鉴权
51
+ */
52
+ headers: {
53
+ [key: string]: string;
54
+ };
55
+ /**
56
+ * 基本请求接口
57
+ */
58
+ host: string;
59
+ constructor(config: AccountCfgType);
60
+ logger(level: LoggerLevel, ...args: any[]): void;
61
+ /**
62
+ * post请求
63
+ * @param url 请求地址
64
+ * @param options 请求参数
65
+ */
66
+ post(url: string, options: any): Promise<import("got").Response<string> | undefined>;
67
+ /**
68
+ * 获取调用凭证
69
+ * @param clientSecret 开发者的Secret
70
+ * @param isRefresh 是否是刷新凭证
71
+ */
72
+ getAccessToken(isRefresh?: boolean): Promise<{
73
+ /**
74
+ * 凭证有效时间,单位:秒 需要在倒计时50秒内刷新凭证
75
+ */
76
+ expires_in: string;
77
+ /**
78
+ * 调用凭证
79
+ */
80
+ access_token: string;
81
+ }>;
82
+ /**
83
+ * wss鉴权
84
+ * @param isAuth 是否鉴权
85
+ */
86
+ wssAuth(isAuth: boolean): Promise<void>;
87
+ /**
88
+ * 获取wss地址
89
+ */
90
+ getWssUrl(): Promise<void>;
91
+ /**
92
+ * 创建wss连接
93
+ */
94
+ createWss(isAuth?: boolean): void;
95
+ payload(payload: string): void;
96
+ /**
97
+ * 事件处理
98
+ */
99
+ intents(data: SubEvent): Promise<void>;
100
+ /**
101
+ * 发送消息
102
+ * @param openid 用户、群openid
103
+ * @param type 请求路径类型
104
+ * @param options 请求参数
105
+ */
106
+ sendMessage(openid: string, type: PathType, options: SendMessageOptions): Promise<SendMessageResponse>;
107
+ /**
108
+ * 构建发送文本消息请求参数
109
+ */
110
+ buildText(content: string, id?: string, seq?: number): SendMessageOptions;
111
+ /**
112
+ * 上传富媒体文件
113
+ * @param openid 用户、群openid
114
+ * @param type 请求类型
115
+ * @param file 文件内容 http、base64、file://
116
+ * @param file_type 文件类型
117
+ */
118
+ uploadMedia(openid: string, type: PathType, file: string, file_type: FileType): Promise<UploadMediaResponse>;
119
+ /**
120
+ * 构建v2接口请求地址
121
+ * @param openid 用户、群openid
122
+ * @param type 请求类型
123
+ * @param apiType v2接口类型
124
+ */
125
+ buildUrl(openid: string, type: PathType, apiType: V2ApiType): string;
126
+ /**
127
+ * 传入一个msg_id或者event_id 返回其对应的key和value
128
+ * @param id 消息id或者事件id
129
+ */
130
+ buildId(id: string): {
131
+ key: IdType;
132
+ value: string;
133
+ };
134
+ /**
135
+ * 构建发送富媒体请求参数
136
+ * 富媒体消息只能单独发送 并且必须进行上传
137
+ * @param file_info 富媒体接口返回的file_info
138
+ * @param id 消息id或者事件id
139
+ */
140
+ buildMedia(file_info: string, id?: string, seq?: number): SendMessageOptions;
141
+ /**
142
+ * 构建发送Markdown模板请求参数
143
+ * @param custom_template_id 模板id
144
+ * @param params 模板参数
145
+ * @param id 消息id或者事件id
146
+ * @param seq 消息序号
147
+ */
148
+ buildTplMarkdown(custom_template_id: string, params: Params, keyboard: SendMessageOptions['keyboard'], id?: string, seq?: number): SendMessageOptions;
149
+ /**
150
+ * 构建发送原生Markdown请求参数
151
+ * @param content markdown文本
152
+ * @param id 消息id或者事件id
153
+ * @param seq 消息序号
154
+ */
155
+ buildRawMarkdown(content: string, keyboard: SendMessageOptions['keyboard'], id?: string, seq?: number): SendMessageOptions;
156
+ /**
157
+ * 构建上传富媒体请求参数
158
+ * @param file 文件内容 http、base64、file://
159
+ * @param file_type 文件类型
160
+ */
161
+ buildUploadMedia(file: string, file_type: FileType): Promise<{
162
+ json: UploadMediaOptions;
163
+ headers: {
164
+ [key: string]: string;
165
+ };
166
+ }>;
167
+ }